
/*
 * 生成饼图
 * data 格式 [{key: "Lithuania",value: 260}, {key: "Ireland",value: 201}];
 * target 目标DivId
 */
function creatChart(data, target){
	var chart = new AmCharts.AmPieChart();
	chart.dataProvider = data;
	chart.titleField = "key";
	chart.valueField = "value";
	chart.outlineColor = "#FFFFFF";
	chart.outlineAlpha = 0.8;
	chart.outlineThickness = 2;
	chart.depth3D = 15;
	chart.angle = 30;
	
	$('#' + target).html('');
	chart.write(target);
	return chart;
}

/*
 * 生成饼图
 * data 格式 [{key: "USA",value: 4025,color: "#FF0F00"}, {key: "China",value: 1882,color: "#FF6600"}];
 * target 目标DivId
 * yAxisTitle Y轴标题
 */
function creatChart2(data, target, yAxisTitle){
	var chart = new AmCharts.AmSerialChart();
	chart.dataProvider = data;
	chart.categoryField = "key";
	chart.depth3D = 20;
	chart.angle = 30;
	
	var categoryAxis = chart.categoryAxis;
	categoryAxis.labelRotation = 30;//X轴标题倾角
	categoryAxis.dashLength = 5;
	categoryAxis.gridPosition = "start";
	
	var valueAxis = new AmCharts.ValueAxis();
	valueAxis.title = yAxisTitle;
	valueAxis.dashLength = 5;
	chart.addValueAxis(valueAxis);
	
	var graph = new AmCharts.AmGraph();
	graph.valueField = "value";
	graph.colorField = "color";
	graph.balloonText = "[[category]]: [[value]]";
	graph.type = "column";
	graph.lineAlpha = 0;
	graph.fillAlphas = 1;
	chart.addGraph(graph);
	
	$('#' + target).html('');
	chart.write(target);
	return chart;
}

/*
 * 生成曲线图
 * data 格式 [{key: "USA",value: 4025,color: "#FF0F00"}, {key: "China",value: 1882,color: "#FF6600"}];
 * target 目标DivId
 * yAxisTitle Y轴标题
 */
function creatChart3(data,target, yAxisTitle){
	var chart3 = new AmCharts.AmSerialChart();
	chart3.pathToImages = "js/amcharts/images/";
	chart3.zoomOutButton = {
	    backgroundColor: '#000000',
	    backgroundAlpha: 0.15
	};
	chart3.dataProvider = data;
	chart3.categoryField = "date";
	chart3.balloon.bulletSize = 5;
	
	chart3.addListener("dataUpdated", function(){
		chart3.zoomToIndexes(chartData3.length - 40, chartData3.length - 1);
	});
	
	// AXES
	// category
	var categoryAxis = chart3.categoryAxis;
	categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
	categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
	categoryAxis.dashLength = 1;
	categoryAxis.gridAlpha = 0.15;
	categoryAxis.position = "top";
	categoryAxis.axisColor = "#DADADA";
	
	// value                
	var valueAxis = new AmCharts.ValueAxis();
	valueAxis.axisAlpha = 0;
	valueAxis.dashLength = 1;
	chart3.addValueAxis(valueAxis);
	
	// GRAPH
	var graph = new AmCharts.AmGraph();
	graph.title = "red line";
	graph.valueField = "value";
	graph.bullet = "round";
	graph.bulletBorderColor = "#FFFFFF";
	graph.bulletBorderThickness = 2; 
	graph.lineThickness = 2;
	graph.lineColor = "#5fb503";
	graph.negativeLineColor = "#efcc26";
	graph.hideBulletsCount = 50;
	chart3.addGraph(graph);
	
	// CURSOR
	chartCursor = new AmCharts.ChartCursor();
	chartCursor.cursorPosition = "mouse";
	chartCursor.pan = true;
	chart3.addChartCursor(chartCursor);
	
	// SCROLLBAR
	var chartScrollbar = new AmCharts.ChartScrollbar();
	chart3.addChartScrollbar(chartScrollbar);
	
	// WRITE
	$('#' + target).html('');
	chart.write(target);
	return chart;
}














